package com.greensam.pixelengine.controller;

import com.greensam.pixelengine.facade.SpaceAnalyzeFacadeService;
import com.greensam.pixelengine.facade.UserFacadeService;
import com.greensam.pixelengine.pojo.base.BaseResponse;
import com.greensam.pixelengine.pojo.entity.UserPo;
import com.greensam.pixelengine.pojo.vo.space.request.*;
import com.greensam.pixelengine.pojo.vo.space.response.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Ma Chengrui
 * @since 2025/9/17 17:26
 */
@Tag(name = "SpaceAnalyzeController", description = "空间分析模块")
@RestController
@RequestMapping("/space/analyze")
@RequiredArgsConstructor
public class SpaceAnalyzeController {

    private final UserFacadeService userFacadeService;
    private final SpaceAnalyzeFacadeService spaceAnalyzeFacadeService;

    @Operation(summary = "空间资源使用分析")
    @PostMapping("/usage")
    public BaseResponse<SpaceUsageAnalyzeVo> getSpaceUsageAnalyze(HttpServletRequest httpServletRequest,
                                                                  @RequestBody SpaceUsageAnalyzeRequest request) {
        UserPo loginUser = userFacadeService.getLoginUser(httpServletRequest);
        return BaseResponse.success(spaceAnalyzeFacadeService.getSpaceUsageAnalyze(request, loginUser.getId()));
    }

    @Operation(summary = "空间图片分类分析")
    @PostMapping("/category")
    public BaseResponse<List<SpaceCategoryAnalyzeVo>> listSpaceCategoryAnalyze(HttpServletRequest httpServletRequest,
                                                                               @RequestBody SpaceCategoryAnalyzeRequest request) {
        UserPo loginUser = userFacadeService.getLoginUser(httpServletRequest);
        return BaseResponse.success(spaceAnalyzeFacadeService.listSpaceCategoryAnalyze(request, loginUser.getId()));
    }

    @Operation(summary = "空间图片标签分析")
    @PostMapping("/tag")
    public BaseResponse<List<SpaceTagAnalyzeVo>> listSpaceTagAnalyze(HttpServletRequest httpServletRequest,
                                                                     @RequestBody SpaceTagAnalyzeRequest request) {
        UserPo loginUser = userFacadeService.getLoginUser(httpServletRequest);
        return BaseResponse.success(spaceAnalyzeFacadeService.listSpaceTagAnalyze(request, loginUser.getId()));
    }

    @Operation(summary = "空间图片大小分析")
    @PostMapping("/size")
    public BaseResponse<List<SpaceSizeAnalyzeVo>> getSpaceUsageAnalyze(HttpServletRequest httpServletRequest,
                                                                       @RequestBody SpaceSizeAnalyzeRequest request) {
        UserPo loginUser = userFacadeService.getLoginUser(httpServletRequest);
        return BaseResponse.success(spaceAnalyzeFacadeService.listSpaceSizeAnalyze(request, loginUser.getId()));
    }

    @Operation(summary = "用户上传行为分析")
    @PostMapping("/user")
    public BaseResponse<List<SpaceUserAnalyzeVo>> getSpaceUsageAnalyze(@RequestBody SpaceUserAnalyzeRequest request) {
        return BaseResponse.success(spaceAnalyzeFacadeService.listSpaceUserAnalyze(request));
    }

    @Operation(summary = "空间使用排名分析")
    @PostMapping("/rank")
    public BaseResponse<List<SpaceVo>> getSpaceUsageAnalyze(HttpServletRequest httpServletRequest,
                                                            @RequestBody SpaceRankAnalyzeRequest request) {
        UserPo loginUser = userFacadeService.getLoginUser(httpServletRequest);
        return BaseResponse.success(spaceAnalyzeFacadeService.listSpaceRankAnalyze(request, loginUser.getId()));
    }
}
